#ifndef SCHEMACOMPONENTFORMULA_H
#define SCHEMACOMPONENTFORMULA_H


#include <string>
#include <vector>
#include <map>
#include "booleanExpression.h"
using namespace std;

// forward declarations.
class Formula;
/*
    Class: SchemaComponentFormula
    Represents a formula of an SQL Table or view.
*/
class SchemaComponentFormula
{
    /* Section: public */
    public:
        /*
            Constructor: Default constructor.
            Initializes the object.
        */
        SchemaComponentFormula(const string & schema_component = "", vector<Formula *> * formulas = NULL);

        /*
            Constructor: Copy constructor.
            Initializes the object as copy from other SchemaComponentFormula object.

            Parameters:
                other - SchemaComponentFormula to copy from
        */
        SchemaComponentFormula(const SchemaComponentFormula & other);

        /*
            Destructor: Default destructor.
            Destroy the object.
        */
        virtual ~SchemaComponentFormula();

        /*
            Method: addFormula
            Adds a formula to collection of formulas

            Parameters:
                formula - Formula object to add.
        */
        void addFormula(Formula * formula);

	/*
            Method: setTableConstraints
	    Sets the collection of formulas of the table
            Parameters:
                constraints - vector of constraints as Boolean Expressions
		tableName - Name of the table.
        */
        void setTableConstraints(vector<BooleanExpression*>* constraints, string table);
	/*
            Method: setTableConstraints
	    Sets the collection of formulas of a collection of tables
            Parameters:
                constraintsmap - map of table names and its vectors of constraints as Boolean Expressions
        */
	void setTableConstraints(map<string, vector<BooleanExpression *>*>* constraintsmap);
        /*
            Method: setFormulas
            Sets the formulas.

        */
        void setFormulas(vector<Formula *> * formulas);

        /*
            Method: setSchemaComponent
            Sets the name of the SchemaComponent object.

            Parameters:
                name - Name of the SchemaComponent object.
        */
        void setSchemaComponent(const string & name);

        /*
            Method: getSchemaComponet
            Returns:
                The name of the SchemaComponent object represented by the formulas.
        */
        string getSchemaComponent();

        /*
            Method: getTableConstraint

            Parameters:
                name - The name of the table

            Returns:
                The constraint as vector<BooleanExpression*>* object of the table given.
        */
        vector<BooleanExpression *> * getTableConstraint(string name) const;

        /*
            Method: getFormula

            Parameters:
                row - The row of the formula wanted.

            Returns:
                The Formula object of the row given.
        */
        Formula * getFormula(unsigned int row) const;

        /*
            Method: getAllFormulas
            Returns:
                All the formulas of the SchemaComponent (1 formula for each SchemaComponent's row)
        */
        vector<Formula *> * getAllFormulas() const;

	/*
	  Method: getTableConstraints
	  Returns: a map of strings and vector of BooleanExpressions representing the name of a table and it's associated constraints
	 */
	map<string,vector<BooleanExpression*>*>* getTableConstraints() const;

        /*
            Method: toString
            Returns:
                A string representation of the formulas of the SchemaComponent object.
        */
        string toString();

        /*
            Method: size
            Returns:
                Number of rows that generates the SchemaComponent.
        */
        unsigned int size();

        /*
            Method: clone
            Returns:
                A clone of this object.
        */
        SchemaComponentFormula * clone();

    /* Section: private */
    private:
        /*
            Variable: formulas
            Type: vector of Formula objects.
            An SQL Table or View has a formula for each row.

            formula[i] = formula for the ith row
        */
        vector<Formula *> * formulas;

	/*
	  Variable: table:formulas
	  Type: map of string, vector<Formula*>*
	  Map between table name and its formulas
	 */
	map<string, vector<BooleanExpression *> * > * table_constraints;
        /*
            Variable: schema_component
            Type: string
            Name of the SchemaComponent object that is represented by the vector of formulas.
        */
        string schema_component;
};

#endif // SCHEMACOMPONENTFORMULA_H
